*************************************************************************************************
**** Multilevel regressions: Including change in local economic activity (Appendix C.7) *********
*************************************************************************************************
clear
use "BHPS_merged.dta"

do "ML programs to add model statistics.do"			

* global with individual-level control variables
	global controls "i.education i.male c.age_cent##c.age_cent i.bornelsewhere2 i.parentsbornelsewhere"

	
******************************** Change in employment share for EU support analysis ***********

	gen D_eu_emplsh_manufact=D3_emplsh_manufact if year==2002	
	replace D_eu_emplsh_manufact=D4_emplsh_manufact if year==2006	

******************************** sort data *************************************
	sort pid waven

		
*************** Regression: EU membership support
	global tradevar "real_gr_imp_CH_d_eu_nl"		

	* baseline
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo EU1
		
	* with change in gross value added
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		reg_gva_all_d_eu_nl ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo EU2					

	* with change in unemployment rate
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		reg_unemp_d_eu ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations
		
		add_scalars_mixed_3level						

		eststo EU3		
		
	* with change in manufacturing employment share
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		D_eu_emplsh_manufact ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo EU4	
		
	* with all three 		
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		D_eu_emplsh_manufact reg_gva_all_d_eu_nl reg_unemp_d_eu ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo EU5

	* write in one table
		esttab EU1 EU2 EU3 EU4 EU5 using "ML regressions econmediators_EUsupport.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
		varwidth(30) nogaps compress ///
		label replace /// 
		scalars(group1N group2N group3N ri1_std ri2_std ri3_std icc1 icc2 icc3 bic) ///
		transform(ln*: exp(@) exp(@)) 	
			
									

*************** Regression: Nationalist attitudes
	global tradevar "real_gr_imp_CH_d3_nl"		

	* baseline
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo NAT1
		
	* with change in gross value added
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		reg_gva_all_d3_nl ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo NAT2					

	* with change in unemployment rate
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		reg_unemp_d3 ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , reml stddeviations
		
		add_scalars_mixed_3level						

		eststo NAT3		
		
	* with change in manufacturing employment share
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		D3_emplsh_manufact ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						

		eststo NAT4	
		
	* with all three 		
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		D3_emplsh_manufact reg_unemp_d3 reg_gva_all_d3_nl ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , reml stddeviations

		add_scalars_mixed_3level						

		eststo NAT5
									
	* write in one table
		esttab NAT1 NAT2 NAT3 NAT4 NAT5 using "ML regressions econmediators_Nationalism.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
		varwidth(30) nogaps compress ///
		label replace /// 
		scalars(group1N group2N group3N ri1_std ri2_std ri3_std icc1 icc2 icc3 bic) ///
		transform(ln*: exp(@) exp(@))		